//引入util js
var _util = require('util/util.js');

//account_service
var _account_service = {
    //买家登录
    usersLogin: function (account, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/account/users/login"),
            data: account,
            method: 'POST',
            success: resolve,
            error: reject,
        });
    },
    //卖家登录
    sellersLogin: function (account, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/account/sellers/login"),
            data: account,
            method: 'POST',
            success: resolve,
            error: reject,
        });
    },
    //买家登出
    usersLogout: function (resolve, reject) {
        _util.request({
            url: _util.getServerURL("/account/users/logout"),
            method: 'POST',
            success: resolve,
            error: reject,
        });
    },
    //卖家登出
    sellersLogout: function (resolve, reject) {
        _util.request({
            url: _util.getServerURL("/account/sellers/logout"),
            method: 'POST',
            success: resolve,
            error: reject,
        });
    },
    //获取短信
    getSMS: function (phone, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/account/login/sendCode"),
            data: { phone },
            method: 'POST',
            success: resolve,
            error: reject,
        });
    },

    //买家短信登录
    usersLoginBySMS: function (phone, code, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/account/users/loginByCode"),
            data: { phone, code },
            method: 'POST',
            success: resolve,
            error: reject,
        });
    },
    //卖家短信登录
    sellersLoginBySMS: function (phone, code, resolve, reject) {
        _util.request({
            url: _util.getServerURL("/account/sellers/loginByCode"),
            data: { phone, code },
            method: 'POST',
            success: resolve,
            error: reject,
        });
    },
    //买家注册账号
    usersRegister: function (formData, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/account/users/register'),
            data: formData,
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //卖家注册账号
    sellersRegister: function (formData, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/account/sellers/register'),
            data: formData,
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //买家重置密码
    usersResetPwd: function (phone, password, code, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/account/users/passwordbycode'),
            data: { phone, password, code },
            method: 'PUT',
            success: resolve,
            error: reject
        });
    },
    //卖家重置密码
    sellersResetPwd: function (phone, password, code, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/account/sellers/passwordbycode'),
            data: { phone, password, code },
            method: 'PUT',
            success: resolve,
            error: reject
        });
    },
    //获取买家信息
    fetchUserinfo: function(resolve, reject) {
        _util.request({
            url: _util.getServerURL('/account/users/info'),
            method: "GET",
            success: resolve,
            error: reject
        });
    },
    updateUserinfo: function(data, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/account/users'),
            method: "PUT",
            success: resolve,
            error: reject,
            data: data
        });
    },
    checkUsername: function(username, resolve, reject) {
        _util.request({
            url: _util.getServerURL('/account/users/check?username=' + username),
            method: "GET",
            success: resolve,
            error: reject
        });
    }
}

module.exports = _account_service;